package com.zzz.common.core.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.zzz.common.core.domain.R;
import com.zzz.common.core.domain.TableDataInfo;

import java.util.List;

/**
 * @BelongsProject: oj-project
 * @BelongsPackage: com.zzz.common.core.controller
 * @Author: zhai
 * @CreateTime: 2025-10-12  23:20
 * @Description: TODO
 * @Version: 1.0
 */
public class BaseController {
    /**
     * @description: 通用返回处理
     * @author: zhai
     * @date: 2025/10/17 16:33
     * @param: [result]
     * @return: com.zzz.common.core.domain.R<java.lang.Void>
     **/
    public R<Void> toR(int result) {
        return result > 0 ? R.success() : R.fail();
    }
    /**
     * @description: 通用返回处理
     * @author: zhai
     * @date: 2025/10/17 16:33
     * @param: [result]
     * @return: com.zzz.common.core.domain.R<java.lang.Void>
     **/
    public R<Void> toR(boolean result) {
        return result ? R.success() : R.fail();
    }
    /**
     * @description: 通用分页返回
     * @author: zhai
     * @date: 2025/10/17 16:34
     * @param: [list]
     * @return: com.zzz.common.core.domain.TableDataInfo
     **/
    public TableDataInfo getDataTable(List<?> list) {
        if (CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
        return TableDataInfo.success(list, new PageInfo<>(list).getTotal());
    }
}
